package bth.reconfs;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class MainLists extends ListFragment{

	private String[][] planningWeek = new String[MainActivity.NB_MAX_LIST][2];

	public MainLists(String[][] planning) {
		planningWeek = planning;
	}

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		ArrayList<HashMap<String, Object>> appItemList= new ArrayList<HashMap<String, Object>>();
		for (int i = 0; i < planningWeek.length; i++) {
			if( planningWeek[i][0] != null ) {
				appItemList.add( fillHashMap(
						planningWeek[i][0],
						planningWeek[i][1]
						));
			}
		}

		// SimpleAdapter qui met en correspondance les items presents dans la list avec ceux de la vue
		SimpleAdapter adapter = new SimpleAdapter (getActivity(), appItemList, R.layout.list_item,
				new String[] {"Title", "Summary"},
				new int[] {R.id.list_item_title, R.id.list_item_resume});
		setListAdapter(adapter);
	}

	// Fill HashMap
	private HashMap<String, Object> fillHashMap(String title, String summary){
		HashMap<String, Object> item = new HashMap<String, Object>();
		item.put("Title", title);
		item.put("Summary", summary);
		return item;
	}
	
	public void onListItemClick (ListView l, View v, int position, long id)
	{
		Toast.makeText(getActivity(), "Clicked on item "+position, Toast.LENGTH_SHORT).show();
		Intent news = new Intent(getActivity(), NewsDetails.class);
		/*picturama.putExtra("nbL", nbL);
		picturama.putExtra("nbC", nbC);
		picturama.putExtra("picture", bitmapToByteArray(imgIsee.getDrawingCache()) );*/
		startActivityForResult(news, 1);
	}
}